package dbOperation;

import library.Book;

import java.sql.SQLException;
import java.sql.Statement;

/**
 * Created by v on 17-5-18.
 */
public class DbUpdate {
    public static boolean Update(Book book){
        String sql=String.format("UPDATE library SET " +
                "name='%s',price=%f,amount=%d,author='%s' WHERE id=%d;",
                book.getName(),book.getPrice(),book.getAmount(),
                book.getAuthor(),book.getId());

        try {
            Statement st=DbConnection.getStatment();
            st.executeUpdate(sql);
        }catch (SQLException ex){
            return false;
        }

        return true;
    }

    public static void main(String[] args) {
        Book book=new Book(1,"我的世界",43,2,"fv");
        System.out.println(DbUpdate.Update(book));
    }
}